<?php 

session_start(); 

require_once "lib/model.inc";
require_once "lib/template.inc";

$stash[current_login] = $_SESSION[current_login];

if ($_SESSION[current_login]) {
    if ($_GET[logout]) {
        session_destroy();
        $stash[show_logout_message] = 1;
        
        header( 'Location: /' ) ;
    }
} else {
    if ($_POST) {
        if ($_POST[login] && $_POST[password]) {
            if ( auth($_POST[login], $_POST[password]) ) {
                $stash[current_login] = $_SESSION[current_login] = $_POST[login];
        
                header( 'Location: /' ) ;
            } else {
                $stash[auth_failed]    = 1;
                $stash[show_auth_form] = 1;
            }
        } else {
            // пароль или логи не введены
            $stash[auth_failed]    = 1;
            $stash[show_auth_form] = 1;
        }
    } else {
        $stash[show_auth_form] = 1;
    }
} 

echo get_template('login', $stash);

?>


